package com.aspose.cells;

import java.util.HashMap;

public class Column {
   private Worksheet b;
   private short c;
   double a;
   private int d = -1;
   private byte e;

   Column(int columnIndex, Worksheet sheet, double defaultWidth) {
      this.c = (short)columnIndex;
      this.b = sheet;
      this.a = defaultWidth;
   }

   Column(int columnIndex, Worksheet sheet, double defaultWidth, Column defaultColumn) {
      this.c = (short)columnIndex;
      this.b = sheet;
      this.a = defaultWidth;
      if (defaultColumn != null && defaultColumn.getIndex() <= columnIndex) {
         this.a(defaultColumn);
      }

   }

   public int getIndex() {
      return this.c;
   }

   void a(int var1) {
      this.c = (short)var1;
   }

   public double getWidth() {
      return this.a;
   }

   public void setWidth(double value) {
      if (value < Double.MIN_VALUE) {
         this.a(true);
      } else {
         this.a = value;
         this.a(false);
      }

      this.c(false);
   }

   int a() {
      double var1 = this.a;
      return zkp.b(var1, this.b.c());
   }

   void b(int var1) {
      this.a = zkp.a((double)var1, this.b.c());
      this.c(false);
   }

   byte b() {
      return (byte)(this.e & 255 & 15);
   }

   void a(byte var1) {
      this.e = (byte)(this.e & 240);
      this.e |= var1;
   }

   public byte getGroupLevel() {
      return this.b();
   }

   int c() {
      return this.d;
   }

   void c(int var1) {
      this.d = var1;
   }

   public boolean isHidden() {
      return this.d();
   }

   public void setHidden(boolean value) {
      this.a(value);
      this.c(false);
      if (!value && this.a == 0.0D) {
         this.a = this.b.getCells().getColumns().b();
      }

   }

   boolean d() {
      return (this.e & 255 & 32) != 0;
   }

   void a(boolean var1) {
      if (!var1) {
         this.e = (byte)(this.e & 223);
      } else {
         this.e = (byte)(this.e | 32);
      }

   }

   void a(Column var1) {
      this.a = var1.a;
      this.d = var1.d;
      this.e = var1.e;
      if (var1.b.c() != this.b.c()) {
         this.d = this.b.c().a(var1.f());
      }

   }

   void a(Column var1, CopyOptions var2) {
      this.c = var1.c;
      this.a = var1.a;
      if (var2 == null || !var2.e) {
         this.b(var1.a());
      }

      this.d = var1.d;
      this.e = var1.e;
      if (var1.c != -1) {
         this.b.getWorkbook().b();
         if (!var2.a && this.b.c() != var1.b.c()) {
            if (var2.b.get(var1.d) != null) {
               this.d = (Integer)var2.b.get(var1.d);
            } else {
               int var3 = var1.d;
               Style var4 = var1.f();
               if (var4 == null) {
                  this.d = -1;
               } else {
                  this.d = this.b.c().a(var4);
               }

               var2.b.put(var3, this.d);
            }
         } else {
            this.d = var1.d;
         }
      } else {
         this.c = -1;
      }

   }

   boolean b(Column var1) {
      if (this.d == var1.d && this.e == var1.e) {
         return Math.abs(this.a - var1.a) <= Double.MIN_VALUE;
      } else {
         return false;
      }
   }

   boolean e() {
      return this.d != -1 && this.d != 15;
   }

   boolean c(Column var1) {
      if (var1 != null) {
         return this.f().equals(var1.f());
      } else {
         return this.d == -1 || this.d == 15;
      }
   }

   void a(byte[] var1) {
      int var2 = com.aspose.cells.b.a.zc.e(var1, 4);
      this.a = Math.floor((double)((var2 & '\uffff') - this.b.c().H()) / 2.56D + 0.5D) / 100.0D;
      if (this.a < 1.0D) {
         this.a = (double)((int)((double)(var2 & '\uffff') * 100.0D / (double)(256 + this.b.c().H()) + 0.5D)) / 100.0D;
      }

      this.d = com.aspose.cells.b.a.zc.e(var1, 6) & '\uffff';
      if (this.d == 65535) {
         this.d = -1;
      } else if (this.d >= this.b.c().B().getCount()) {
         this.d = 15;
      }

      this.a((byte)(var1[9] & 255 & 7));
      int var3 = var1[8] & 255 & 1;
      if (var3 != 0) {
         this.a(true);
      }

      if ((var1[8] & 255 & 4) != 0) {
         this.c(true);
      }

      var3 = var1[9] & 255 & 16;
      if (var3 != 0) {
         this.b(true);
      }

   }

   public void applyStyle(Style style, StyleFlag flag) {
      Cells var3 = this.b.getCells();
      RowCollection var4 = this.b.getCells().getRows();
      var3.n();
      if (flag.getAll()) {
         this.a(style);

         for(int var12 = 0; var12 < var3.getRows().getCount(); ++var12) {
            Row var14 = var3.getRows().getRowByIndex(var12);
            Cell var15 = var14.getCellOrNull(this.c);
            if (var15 != null) {
               var15.b(this.d);
            } else if (var14.j()) {
               var15 = var14.c(this.c);
               var15.b(this.d);
            }
         }

      } else {
         HashMap var5 = new HashMap();
         boolean var6 = false;
         Style var7 = null;

         int var13;
         for(int var8 = 0; var8 < var3.getRows().getCount(); ++var8) {
            Row var9 = var3.getRows().getRowByIndex(var8);
            Cell var10 = var9.getCellOrNull(this.c);
            if (var10 == null && var9.j()) {
               var10 = var9.c(this.c);
            }

            if (var10 != null) {
               var13 = var10.r();
               if (var5.get(var13) != null) {
                  var10.b((Integer)var5.get(var13));
               } else {
                  Style var11 = var10.o();
                  zakq.a(style, var11, flag);
                  var10.a(var11);
                  var5.put(var13, var10.s());
               }
            }
         }

         var13 = this.d;
         var7 = this.getStyle();
         zakq.a(style, var7, flag);
         this.a(var7);
      }
   }

   public Style getStyle() {
      Style var1 = new Style(this.b.c());
      if (this.d != -1 && this.d != 15) {
         var1.a(this.b.c(), this.d);
      } else {
         var1.a((WorksheetCollection)this.b.c(), (int)15);
      }

      return var1;
   }

   void a(Style var1) {
      this.d = this.b.c().a(var1);
   }

   Style f() {
      return this.d != -1 && this.d != 15 ? this.b.c().B().a(this.d) : this.b.c().D();
   }

   boolean g() {
      return (this.e & 255 & 16) != 0;
   }

   void b(boolean var1) {
      if (var1) {
         this.e = (byte)(this.e | 16);
      } else {
         this.e = (byte)(this.e & 239);
      }

   }

   boolean h() {
      return (this.e & 255 & 64) != 0;
   }

   void c(boolean var1) {
      if (var1) {
         this.e = (byte)(this.e | 64);
      } else {
         this.e = (byte)(this.e & 191);
      }

   }

   boolean i() {
      return (this.e & 255 & 128) != 0;
   }

   void d(boolean var1) {
      if (var1) {
         this.e = (byte)(this.e | 128);
      } else {
         this.e = (byte)(this.e & 63);
      }

   }

   boolean j() {
      return this.e() || this.isHidden() || this.getGroupLevel() != 0 || this.a != this.b.getCells().getColumns().b();
   }
}
